def maxxes(a):
    if a == 1: return False
    b = True
    c = a-1
    while c > 1:
        if not a % c:
            b = False
            break
        c -= 1
    return b

d = input()
e = []
for i in range(len(d)):
    for c in range(i + 1, len(d) + 1):
        a = int(d[i:c])
        if maxxes(a):
            e += [a]
print(max(e) if e else 0)
